package com.lrkj.payfee.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.lrkj.common.core.domain.entity.SysUser;
import com.lrkj.common.utils.DateUtils;
import com.lrkj.common.utils.SecurityUtils;
import com.lrkj.common.utils.StringUtils;
import com.lrkj.common.utils.uuid.IdUtils;
import com.lrkj.payfee.vo.ComputePayFeeLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lrkj.payfee.mapper.ComputePayFeeLogMapper;
import com.lrkj.payfee.domain.ComputePayFeeLog;
import com.lrkj.payfee.service.IComputePayFeeLogService;

/**
 * 计算费用日志记录Service业务层处理
 *
 * @author yajun_ren
 * @date 2022-08-04
 */
@Service
public class ComputePayFeeLogServiceImpl implements IComputePayFeeLogService
{
    @Autowired
    private ComputePayFeeLogMapper computePayFeeLogMapper;

    /**
     * 查询计算费用日志记录
     *
     * @param id 计算费用日志记录ID
     * @return 计算费用日志记录
     */
    @Override
    public ComputePayFeeLog selectComputePayFeeLogById(String id)
    {
        return computePayFeeLogMapper.selectComputePayFeeLogById(id);
    }

    /**
     * 查询计算费用日志记录列表
     *
     * @param computePayFeeLog 计算费用日志记录
     * @return 计算费用日志记录
     */
    @Override
    public List<ComputePayFeeLog> selectComputePayFeeLogList(ComputePayFeeLog computePayFeeLog)
    {
        return computePayFeeLogMapper.selectComputePayFeeLogList(computePayFeeLog);
    }

    /**
     * 新增计算费用日志记录
     *
     * @param computePayFeeLog 计算费用日志记录
     * @return 结果
     */
    @Override
    public int insertComputePayFeeLog(ComputePayFeeLog computePayFeeLog)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        computePayFeeLog.setCreateTime(DateUtils.getNowDate());
        computePayFeeLog.setCreateBy(user.getNickName());
        if(StringUtils.isEmpty(computePayFeeLog.getId())){
            computePayFeeLog.setId(IdUtils.simpleUUID());
        }
        return computePayFeeLogMapper.insertComputePayFeeLog(computePayFeeLog);
    }

    /**
     * 修改计算费用日志记录
     *
     * @param computePayFeeLog 计算费用日志记录
     * @return 结果
     */
    @Override
    public int updateComputePayFeeLog(ComputePayFeeLog computePayFeeLog)
    {
        computePayFeeLog.setUpdateTime(DateUtils.getNowDate());
        return computePayFeeLogMapper.updateComputePayFeeLog(computePayFeeLog);
    }

    /**
     * 批量删除计算费用日志记录
     *
     * @param ids 需要删除的计算费用日志记录ID
     * @return 结果
     */
    @Override
    public int deleteComputePayFeeLogByIds(String[] ids)
    {
        return computePayFeeLogMapper.deleteComputePayFeeLogByIds(ids);
    }

    /**
     * 删除计算费用日志记录信息
     *
     * @param id 计算费用日志记录ID
     * @return 结果
     */
    @Override
    public int deleteComputePayFeeLogById(String id)
    {
        return computePayFeeLogMapper.deleteComputePayFeeLogById(id);
    }

    @Override
    public List<ComputePayFeeLogVo> listByIds(String[] ids) {
        return computePayFeeLogMapper.selectByIds(Arrays.stream(ids).distinct().collect(Collectors.toList()));
    }

    /**
     * 批量新增计算费用日志记录信息
     *
     * @param computePayFeeLogs 计算费用日志记录对象
     */
    public int batchAddData(List<ComputePayFeeLog> computePayFeeLogs)
    {
           return computePayFeeLogMapper.batchAddData(computePayFeeLogs);
    }
}
